<%--
  Created by IntelliJ IDEA.
  User: nicks
  Date: 2021/3/24
  Time: 17:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<script src="<%=request.getContextPath()%>/js/jQuery.js"></script>
<!-- 引入 layui.css -->
<link rel="stylesheet" href="//unpkg.com/layui@2.6.7/dist/css/layui.css">
<!-- 引入 layui.js -->
<script src="//unpkg.com/layui@2.6.7/dist/layui.js"></script>
<body>
<div style="display: flex; background-color: #393D49">
    <div style="flex:2"></div>
    <div style="flex:6">
        <ul class="layui-nav" lay-filter="">
            <li class="layui-nav-item"><a href="<%= request.getContextPath()%>/ces.jsp">首页</a></li>
            <li class="layui-nav-item "><a href="">寻找菜谱</a></li>
            <li class="layui-nav-item"><a href="<%=request.getContextPath()%>/upload.jsp">发布菜谱</a></li>
            <li class="layui-nav-item" style="position: relative;right: 20px">
                <a href="javascript:;"><div><%
                    Cookie[] cookies = request.getCookies();
                    String token = null;
                    if (cookies != null) {
                        for (Cookie cookie : cookies) {
                            if (cookie.getName().equals("token")) {
                                token = cookie.getValue();
                            }
                        }
                    }
                    if (token == null) {
                        out.print("<span onclick=\"location.href = 'login.jsp'\">登录</span>");
                    } else {
                        UserService userService = new UserService();
                        User user = userService.getUserByToken(token);
                        out.print("<span>" + user.getName() + "</span>");
                    }
                %></div></a>
                <dl class="layui-nav-child"> <!-- 二级菜单 -->
                    <dd><a href="">个人中心</a></dd>
                    <dd><a href="<%= request.getContextPath()%>/login.jsp">退出</a></dd>
                </dl>
            </li>
        </ul>
    </div>
    <div style="flex:2"></div>
</div>
</body>
<script>
    layui.use('element', function () {
        var element = layui.element;
    });
</script>
</html>
